home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / node_pq.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  1.9 KB  |  62 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  node_pq.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef NODE_PQ_H
  16. #define NODE_PQ_H
  17.  
  18. #include <LEDA/graph.h>
  19.  
  20.  
  21. //------------------------------------------------------------------------------
  22. // node priority queues
  23. //------------------------------------------------------------------------------
  24.  
  25. #ifndef FHEAPH
  26. #include <LEDA/f_heap.h>
  27. #endif
  28.  
  29. #define node_pq(itype) name2(itype,node_pq)\
  30.  
  31. #define node_pqdeclare(itype)\
  32. \
  33. class node_pq(itype) : private f_heap{\
  34. \
  35. int cmp(ent& x, ent& y)  const { return compare(*(itype*)&x,*(itype*)&y); }\
  36. void print_key(ent& x)   const { Print(*(itype*)&x); }\
  37. void print_inf(ent& x)   const { Print(*(node*)&x);  }\
  38. void clear_key(ent& x)   const { Clear(*(itype*)&x); }\
  39. void clear_inf(ent& x)   const { Clear(*(node*)&x);  }\
  40. void copy_key(ent& x)    const { x = Copy(*(itype*)&x);  }\
  41. void copy_inf(ent& x)    const { x = Copy(*(node*)&x);   }\
  42. graph_array(node) I;\
  43. \
  44. public:\
  45.  node_pq(itype)(const graph& G) { I.init(G,0); }\
  46. ~node_pq(itype)()               { I.clear(); }\
  47. \
  48.  void decrease_inf(node v, itype i)\
  49.                       { f_heap::decrease_key(f_heap_item(I.inf(v)),Ent(i)); }\
  50.  void insert(node v,itype i)\
  51.                       { ent x=Ent(i);I.entry(v)=(ent)f_heap::insert(x,ent(v)); }\
  52.  void del(node v)     { f_heap::del_item(f_heap_item(I.inf(v)));   }\
  53.  node find_min()      { return (node)f_heap::inf(f_heap::find_min());   }\
  54.  node del_min()       { node v = find_min(); f_heap::del_min(); return v; }\
  55.  void clear()         { f_heap::clear(); }\
  56.  int empty()          { return f_heap::empty(); }\
  57. \
  58. };
  59.  
  60. #endif
  61.